package com.sports.demo.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sports.demo.basic.BasicController;
import com.sports.demo.model.User;
import com.sports.demo.model.Venue;
import com.sports.demo.req.NameReq;
import com.sports.demo.service.VenueService;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 场馆 前端控制器
 * </p>
 *
 * @author SRG
 * @since 2022-03-13
 */
@RestController
@RequestMapping("/venue")
public class VenueController extends BasicController<VenueService, Venue> {

  @PostMapping({"getPage"})
  public IPage<Venue> page(@RequestBody NameReq req) {
    LambdaQueryWrapper<Venue> query = Wrappers.lambdaQuery(Venue.class).orderByDesc(Venue::getId);
    if (StringUtils.hasText(req.getName())) {
      query.like(Venue::getVenueName, req.getName());
    }
    return getBasicService().page(req.getPlusPage(), query);
  }

  @PostMapping("getlist")
  @ApiOperation(value="列表", notes="")
  public List<Venue> getlist() {
    return getBasicService().list(new LambdaQueryWrapper<Venue>()
        .orderByAsc(Venue::getId));
  }

}
